// 导入模块
const mysql = require("mysql2");

// 创建一个数据库连接
const connectionPool = mysql.createPool({
  host: "localhost",
  port: 3306,
  user: "root",
  password: "Gaochen6812046",
  database: "coderhub",
});

// 2.获取连接是否成功
connectionPool.getConnection((err, connection) => {
  if (err) {
    console.log("获取连接失败", err);
    return;
  }
  connection.connect(err => {
    if (err) {
      console.log("和数据库交互失败", err);
    } else {
      console.log("和数据库交互成功，请进行操作~");
    }
  });
});

const connection = connectionPool.promise();

module.exports = connection;
